From 97ddd71343e638dc9cde231252d16ccf61d3c5f5 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 2 Jun 2025 10:57:57 +0200 Subject: [PATCH] fix(windows): when deleting a file use safe long windows path will avoid getting a content access denied error because some paths is too long for windows default limit and has to use the special syntax for long path see https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry Signed-off-by: Matthieu Gallien --- src/common/filesystembase.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index 41919e59f..38747f870 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -546,22 +546,23 @@ QString FileSystem::fileSystemForPath(const QString &path) bool FileSystem::remove(const QString &fileName, QString *errorString) { + const auto &windowsSafeFileName = FileSystem::longWinPath(fileName); #ifdef Q_OS_WIN // You cannot delete a read-only file on windows, but we want to // allow that. - setFileReadOnly(fileName, false); + setFileReadOnly(windowsSafeFileName, false); #endif - const auto deletedFileInfo = QFileInfo{fileName}; + const auto deletedFileInfo = QFileInfo{windowsSafeFileName}; if (!deletedFileInfo.exists()) { - qCWarning(lcFileSystem()) << fileName << "has been already deleted"; + qCWarning(lcFileSystem()) << windowsSafeFileName << "has been already deleted"; } - QFile f(fileName); + QFile f(windowsSafeFileName); if (!f.remove()) { if (errorString) { *errorString = f.errorString(); } - qCWarning(lcFileSystem()) << f.errorString() << fileName; + qCWarning(lcFileSystem()) << f.errorString() << windowsSafeFileName; #if defined Q_OS_WIN const auto permissionsDisplayHelper = [] (std::filesystem::perms currentPermissions) { @@ -580,10 +581,10 @@ bool FileSystem::remove(const QString &fileName, QString *errorString) << unitaryHelper(std::filesystem::perms::others_exec, 'x'); }; - const auto unsafeFilePermissions = filePermissionsWin(fileName); + const auto unsafeFilePermissions = filePermissionsWin(windowsSafeFileName); permissionsDisplayHelper(unsafeFilePermissions); - const auto safeFilePermissions = filePermissionsWinSymlinkSafe(fileName); + const auto safeFilePermissions = filePermissionsWinSymlinkSafe(windowsSafeFileName); permissionsDisplayHelper(safeFilePermissions); #endif -- 2.30.2